package cn.suxiaoxiang.mmskillbar.Commands;

import cn.suxiaoxiang.mmskillbar.MMskillBar;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.event.Listener;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author Corder-Suxiaoxiang
 * @UserName 程序员_Suxiaoxiang
 * @date 2025/1/24 17:29
 * @Version 1.0
 */
public class commands implements CommandExecutor, TabExecutor, Listener {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        String version = MMskillBar.main.getDescription().getVersion();
        // 检查发送命令的玩家是否是 OP
        if (!sender.isOp()) {
            sender.sendMessage(ChatColor.RED + "[MMskillBar] 你没有权限执行此命令！");
            // 结束命令执行
            return false;
        }
        if (args.length == 0) {
            sender.sendMessage(ChatColor.WHITE + ">>" + ChatColor.AQUA + "作者介绍" + ChatColor.WHITE + "<<");
            sender.sendMessage("§a版本："+version);
            sender.sendMessage("§a作者：程序员_Suxiaoxiang");
            sender.sendMessage(ChatColor.WHITE + ">>" + ChatColor.AQUA + "指令界面" + ChatColor.WHITE + "<<");
            sender.sendMessage(ChatColor.YELLOW + "--------------------");
            sender.sendMessage(ChatColor.YELLOW + "/mms reload" + " " + ChatColor.DARK_GREEN + "重载插件");
            sender.sendMessage(ChatColor.YELLOW + "--------------------");
        } else if (args.length == 1) {
            if ("reload".equals(args[0])) {
                MMskillBar.main.reloadConfig();  // 重新加载配置
                // 每次重载后重新获取配置中的值
                Set<String> skills = MMskillBar.main.getConfig().getConfigurationSection("Skills").getKeys(false);
                sender.sendMessage(ChatColor.GREEN + "[MMskillBar] 插件重载成功！");
                sender.sendMessage(ChatColor.GREEN + "[MMskillBar] 已加载"+skills.size()+"个技能！");
            }
        }
        return false;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        if (args.length == 1) {
            List<String> list = new ArrayList<>();
            list.add("reload");
            return list;
        }
        return null;
    }
    }

